<template>
	<view class="work_detail">
		<swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration"
		 :circular="circular">
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<view class="box1">
			<view class="price">
				赞：{{detailInfo.thumbsUp}}，点赞
			</view>
			<view class="work_name">
				{{detailInfo.title}}
			</view>
		</view>
		<view class="line"></view>
		<view class="box2">
			<view class="tit">详情介绍</view>
			<view class="detContent">
				<rich-text  :nodes="detailContent.content"></rich-text>
			</view>
		</view>
		<view class="goods_nav">
			<uni-goods-nav :fill="true"  :options="options" :buttonGroup="buttonGroup"  @click="onClick" @buttonClick="buttonClick" />
		</view>
	</view>
	
</template>

<script>
	import uniGoodsNav from '@/components/uni-goods-nav/uni-goods-nav.vue'
	export default {
		data() {
			return {
				id:0,
				swipers:[],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				circular: true,
				detailInfo:{},
				detailContent:{},
				//购物导航配置
				 options: [{
				            icon: 'headphones',
				            text: '客服'
				        }, {
				            icon: 'shop',
				            text: '店铺',
				            info: 2,
				            infoBackgroundColor:'#007aff',
				            infoColor:"red"
				        }, {
				            icon: 'cart',
				            text: '购物车',
				            info: 2
				        }],
				    buttonGroup: [{
				          text: '加入购物车',
				          backgroundColor: '#ff0000',
				          color: '#fff'
				        },
				        {
				          text: '立即购买',
				          backgroundColor: '#ffa200',
				          color: '#fff'
				        }
				    ]
			}
		},
		  components: {uniGoodsNav},
		methods: {
			async getSwipers(){
				const res = await this.$myRequest({
					url:"/works/workDetailSwiperImgList/"+this.id
				});
				console.log(res)
				this.swipers = res.data;
			},
			async getWorkDetailInfo(){
				const res = await this.$myRequest({
					url:"/works/getWorkDetailInfo/"+this.id
				});
				console.log(res);
				this.detailInfo = res.data[0];
			},
			async getWorkDetailContent(){
				const res = await this.$myRequest({
					url:"/works/getWorkDetailContent/"+this.id
				});
				
				this.detailContent = res.data[0];
				//正则替换图片不满屏问题
				this.detailContent.content = this.detailContent.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ');
				console.log(this.detailContent);
			},
			onClick (e) {
			        uni.showToast({
			          title: `点击${e.content.text}`,
			          icon: 'none'
			        })
			      },
			      buttonClick (e) {
			        console.log(e)
			        this.options[2].info++
			      }
		},
		onLoad(options){
			this.id = options.id
			console.log("id is:"+this.id)
			this.getSwipers();
			this.getWorkDetailInfo();
			this.getWorkDetailContent();
		}
		
	}
</script>

<style lang="scss">
.work_detail{
	swiper{
		height: 700rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.box1{
		padding:10px;
		.price{
			font-size: 35rpx;
			color:$shop-color
		}
		.work_name{
			font-size: 32rpx;
			line-height: 70rpx;
		}
	}
	.line{
		width: 100%;
		height: 10rpx;
		line-height: 5rpx;
		background: #eee;
	}
	.box2{
		padding: 10rpx;
		.tit{
			font-size: 32rpx;
			border-bottom: 1px solid #EEEEEE;
			line-height:70rpx ;
		}
		.detContent{
			padding:15rpx;
			line-height: 50rpx;
		}
	}
	.goods_nav{
		position: fixed;
		bottom: 0;
		width: 100%;
	}
	padding-bottom: 20rpx;
}
</style>
